package com.suyang.syt.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.suyang.syt.model.dto.AjaxObj;
import com.suyang.syt.service.interfaces.InitService;
import com.suyang.syt.util.EmptyUtil;
import com.suyang.syt.util.StringUtil;

@Controller
public class InitController {

	@Autowired
	private InitService initService;

	@RequestMapping(value = "/init", method = RequestMethod.GET)
	public String initSYS(String q, Model model) {
		if (EmptyUtil.isNotEmpty(q)) {
			model.addAttribute("method", q);
		}
		return "initSYS";
	}

	@RequestMapping(value = "/initSYS", method = RequestMethod.POST)
	@ResponseBody
	public AjaxObj initSYS(HttpServletRequest request, String method) {
		try {
			return initService.addInit(method);
		} catch (Exception e) {
			return new AjaxObj(0, StringUtil.ERROR_MSG);
		}
	}

}